import axios from "axios";
import { ElMessageBox } from "element-plus";
import {useRouter} from "vue-router"

const http = axios.create({
  baseURL: "/api",
  timeout: 1000 * 10,
});

//请求拦截器
http.interceptors.request.use((confing) => {
  confing.headers.authorization = sessionStorage.getItem("token")
  
  return confing;

});

//相应拦截器
http.interceptors.response.use((confing) => {
  if (confing.data.state) {
    
    return confing;

  } else {
    if(confing.data.code===10022 || confing.data.code===10044){

       let router = useRouter()
       router.push({
        path:'/'
       }) 
    }
    console.log(confing,"i7878787");
    ElMessageBox.alert(confing.data.msg, "error", {
      type: "error",
      // icon: markRaw(Delete),
    });
    return new Promise.reject(confing.data.msg)
  }
});
export default http;
